package Handler;

import Exception.InvalidFormatException;
import Exception.InvalidTypeFormatException;
import formatter.FormatterJson;
import formatter.FormatterTrad;
import formatter.IFormatter;
import logging.Record;

public class ConsoleHandler extends Handler{

	public ConsoleHandler() {
		super();
	}

	/*
	 * printed the message according to associated format
	 */
	
	@Override
	public void write(Record record) {
		try {
			IFormatter formatter = new FormatterTrad(record.getFormatConsole());
			formatter.setChainFormatter(new FormatterJson(record.getFormatConsole()));
			String messageFormatted = formatter.applyFormat(record);
			record.setMessage(messageFormatted);
			if (messageCanWrite(record)){
				System.out.println(messageFormatted);
			}
		} catch (InvalidTypeFormatException | InvalidFormatException e) {
			e.printStackTrace();
		}
	}

	@Override
	public String getName() {
		return "console";
	}

}
